import React from 'react'
import DownloadHint from "../DownloadHint/DownloadHint";
import AppLayout from "../../layouts/AppLayout";
import {GlobalStore} from "../../context";

class DownloadWrapper extends React.Component {

    constructor(props) {
        super(props)
        this.state = {
            downloadShow: true,
        }
    }

    componentDidMount() {
        this.setDownloadShow()
    }

    setDownloadShow = () => {
        const downloadShow = this.context.downloadApp.show
        this.setState({
            downloadShow,
        })
    }

    hidden = () => {
        this.context.downloadApp.hidden()
        this.setState({
            downloadShow: false,
        })
    }

    render() {
        const download = this.state.downloadShow
        return <React.Fragment>
            {
                download
                    ? <div
                        style={{
                            position: 'sticky',
                            top: 0,
                            left: 0,
                            zIndex: 9999,
                        }}
                    >
                        <DownloadHint onHidden={this.hidden}/>
                    </div>
                    : null
            }
            {this.props.children}
        </React.Fragment>
    }

}

DownloadWrapper.contextType = GlobalStore

export default DownloadWrapper